//
//  SYVersionManger.m
//  siyanone
//
//  Created by LK-IOS on 2018/3/21.
//  Copyright © 2018年 LK-News. All rights reserved.
//

#import "SYVersionManger.h"

@interface SYVersionManger()


@end


@implementation SYVersionManger


static SYVersionManger *_instance;


+ (instancetype)allocWithZone:(struct _NSZone *)zone
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [super allocWithZone:zone];
    });
    return _instance;
}

+ (instancetype)sharedInstance
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc] init];
    });
    return _instance;
}

- (id)copyWithZone:(NSZone *)zone
{
    return _instance;
}

-(void)loadAppVersionInformation
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setObject:[NSNumber numberWithInteger:[deviceType integerValue]] forKey:@"deviceType"];
    [dict setObject:[NSNumber numberWithInteger:[shellIndex integerValue]] forKey:@"shellIndex"];
    [BaseNetRequest sessionRequestWithparameters:dict method:GETMethod requstType:GetAppVersion WithSuccessBlock:^(NSDictionary *resultDict) {
        DDLog(@"resultDict %@" , resultDict)//isOnlineForAudit  isOnline  isOnlineForAudit1
        if ([resultDict[@"code"] integerValue] == 200) {
            BOOL isOnLine = [resultDict[@"result"][@"isOnline"] boolValue];
            [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:isOnLine] forKey:@"isOnline"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
    } failBlock:^(NSError *error) {
        DDLog(@"error %@" , error)
    }];
}

-(void)upLoadJpushID
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setObject:[NSNumber numberWithInteger:[deviceType integerValue]] forKey:@"deviceType"];
    [dict setObject:[NSNumber numberWithInteger:[shellIndex integerValue]] forKey:@"shellIndex"];
    [dict setValue:[SYUserInformation sharedInstance].registrationID forKey:@"registrationId"];
    
    if (![SYUserInformation sharedInstance].registrationID.length) {
        DDLog(@"--------------------------- 调用上传极光ID，ID为空 ------------------------------------------------")
    }
    
    [BaseNetRequest sessionRequestWithparameters:dict method:POSTMethod requstType:PostJpushId WithSuccessBlock:^(NSDictionary *resultDict) {
        DDLog(@"resultDict = %@" , resultDict)
        if ([SYUserInformation sharedInstance].registrationID.length) {
            DDLog(@"--------------------------- 调用上传极光ID成功，ID为%@" , [SYUserInformation sharedInstance].registrationID)
        }
    } failBlock:^(NSError *error) {
        
        DDLog(@"--------------------------- 调用上传极光ID，ID为空 ------------------------------------------------")
    }];
}

-(BOOL)isCannormalJumpTab
{
    NSNumber *isOnline = [[NSUserDefaults standardUserDefaults] objectForKey:@"isOnline"];
    if ([[[UIDevice currentDevice] model] isEqualToString:@"iPhone"]) {
        if ([isOnline boolValue]) {
            return YES;
        }else{
            NSInteger versionDay = [NSDate hadStartedTimeWithBeginTime:isOnLineTime];
            if (versionDay >=5) {
                return YES;
            }else{
                return NO;
            }
        }
    }else{
        return NO;
    }
    
    
}

@end
